package 笔试2.wangyi.two;


import org.junit.Test;

import java.util.*;

public class Main {
    static int min3(int a,int b,int c){
        int min1 = Math.min(a, b);
        int min2 = Math.min(c,min1);
        return min2;
    }

    static Long[] p;
    public static void main(String[] args) {
//        p = new int[]{1,2,4,8,16,32};
        Scanner sc = new Scanner(System.in);
        Long num = Long.parseLong(sc.nextLine());


//        int tS=17,ci=0;
        Long tS=num;int ci=0;
        List<Long> list = new ArrayList<>();
        Long c= Long.valueOf(1);
        int y=0;
        while(c<=Long.valueOf(214748)){
            list.add(c);
            c= ercifang(y);y++;
//            System.out.println(""+c);
        }

        p=new Long[list.size()];
        for (int i = 0; i < list.size(); i++) {
            p[i]=list.get(i);
        }
        if(tS==0){
            System.out.println(-1);
            return;
        }
        System.out.println(minGS(tS, ci)==9999?-1:minGS(tS, ci));
    }

    private static Long ercifang(int i) {
        Long res = Long.valueOf(1);
        while(i>=1){
            res*=2;
            i--;
        }
        return res;
    }

    //最少币个
    static Map<String, Integer> map =new HashMap<>();
    private static int minGS(Long tS, int ci) {
        String key = tS+","+ci;
        if(ci==p.length){
            if(tS==0)return 0;//最少币数r0
            return 9999;
        }

        if(map.containsKey(key)){
            return map.get(key);
        }

        int curRES = min3(
                minGS(tS-p[ci],ci+1) +1,
                minGS(tS+p[ci],ci+1) +1,
                minGS(tS,ci+1)
        );
        map.put(key,curRES);
        return curRES;
    }
}
